
/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.koushikdutta.async.utils;

import com.koushikdutta.async.util.LogUtil;
import ohos.app.Context;

import java.io.File;
import java.io.IOException;

/**
 * Created by Yan Zhenjie on 2016/7/7.
 */
public class FileUtils {

    private static final String CACHE_PATH = "asynccache";


    /**
     * 创建本地txt文件
     *
     * @param fileName Here is a note copy.
     * @param context Here is a note copy
     * @return name Here is a note copy.
     * @throws null Here is a note copy.
     */
    public static String createFile(Context context, String fileName) throws IOException {
        String filePath = context.getFilesDir() + File.separator + CACHE_PATH;
        File dir = new File(filePath);
        if (!dir.exists()) {
            if(dir.mkdirs()){
                LogUtil.info("dir","ok");
            }
        }
        File checkFile = new File(filePath + File.separator + fileName);
        return checkFile.getCanonicalPath();
    }
    /**
     * Here is a note copy.
     *
     * @param context Here is a note copy
     * @return Here is a note copy
     */
    public static File createCach(Context context) {
        String filePath = context.getFilesDir() + File.separator + CACHE_PATH;
        File dir = new File(filePath);
        if (!dir.exists()) {
            if(dir.mkdirs()){
                LogUtil.info("dir","ok");
            }
        }
        File checkFile = new File(filePath);
        return checkFile;
    }
}
